package com
{
	//http://blogagic.com/18/flex-component-life-cycle#drawingchanges
	//http://vipingupta.blog.com/2012/04/12/flex-component-life-cycle-part-2/
	import flash.events.MouseEvent;
	
	import mx.controls.CheckBox;
	import mx.core.UIComponent;
	
	public class CustomTextBox extends UIComponent
	{
		private var _widthBox:Number = 0;
		public function CustomTextBox()
		{
			super();
			this.addEventListener(MouseEvent.CLICK, onClickMouseEvent);
			trace("Coustruct Phase");
		}

		public function get widthBox():Number
		{
			return this._widthBox;
		}

		public function set widthBox(value:Number):void
		{
			this._widthBox = value;
			invalidateDisplayList();
			trace("Configuration Phase");
		}
		
		override protected function commitProperties():void
		{
			trace("validation -- Commiting properties ---");
		}
		
		override protected function createChildren():void
		{
			var objcheckBox:CheckBox = new CheckBox();
			objcheckBox.width =100;
			objcheckBox.height = 50;
			this.addChild(objcheckBox);
			trace("CreateChildren - After Preinitialize, occours only once");
		}
		
		override protected function measure():void
		{
			measuredHeight = 100;
			measuredWidth = this._widthBox;
			trace("Validation: Measured Height");
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			this.graphics.clear();
			this.graphics.lineStyle(1,0x112222,1);
			this.graphics.beginFill(0x444444,1);
			this.graphics.drawRect(0,0,this._widthBox,100);
			this.graphics.endFill();
			trace("Validation -> UpdateDisplayList");
		}
		
		public function onClickMouseEvent(e:MouseEvent):void
		{
			trace("Mouse Clicked!");
			this._widthBox = 50;
		}

	}
}